<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<%@ page session="false"%>
<%@ page contentType="text/html; charset=UTF-8"%>

<div id="zhishilist"></div>

<div id="pagelist">
	<a href="javascript:void(0);" title="上一页">上一页</a>
	<a href="javascript:void(0);" title="下一页">下一页</a>
</div>

<sec:authorize ifAnyGranted="ROLE_ADMIN,ROLE_USER"></sec:authorize>
<tiles:importAttribute/>

<script language="JavaScript" type="text/javascript">
	//<![CDATA[
	$(function(){
		me='<sec:authentication property="name"/>';
		
	});
	//]]>
</script>

<script language="JavaScript" type="text/javascript">
	//<![CDATA[
	$(function(){
		try{
			user='${username}';
			var curPage=1;
			function loadPage(page){
				try{
				$.getJSON("zhishi/list",{pageNo:page,pageSize:10,userName:user},function(json){
					try{
						var data=json.data;
						var html=new Array();
						for(var i=0;i<data.length;i++){
							//下面的这段过程应该可以独立出来作为一个组件
							//对于json方面的拼接字符串的操作，应该可以更简洁点
							var zhishi=data[i];
							html.push('<div class="node">');
							html.push('<div class="head">'+zhishi.title+'<\/div>');								
							html.push('<div class="body">'+zhishi.content+'<\/div>');
							html.push('<div class="foot">');
							html.push('<span class="time">'+zhishi.indb+'<\/span>');
							html.push('<span class="tags">标签:'+zhishi.tags+'<\/span>');								
							html.push('<\/div>');
							html.push('<\/div>');
						}
						html=html.join("\n");
						$("#zhishilist").html(html);
					}catch(e){alert(e);}
				});	
				}catch(e){alert("a"+e);}
			}
			
			//前一页
			$("#pagelist a:first").click(function(event){
					if(curPage>1){
						var page=curPage-1;
						loadPage(page);
						curPage-=1;
					}
					return false;
				});
			//后一页
			$("#pagelist a:last").click(function(event){							
					var page=curPage+1;
					loadPage(page);
					curPage+=1;
					return false;
				});
			
			loadPage(curPage);
		}catch(e){alert(e);}
	});
	//]]>
</script>